package com.tools.ad.adscene.outer;

import android.view.View;

import com.hm.ads.sdk.HmAdsSDK;
import com.hm.adsbuisiness.bean.dapweather.HmWeatherAdPlace;
import com.hm.base.android.mob.AMApplication;
import com.tools.ad.ADModule;
import com.tools.ad.EntranceType;
import com.tools.ad.R;
import com.tools.ad.adscene.AdScene;
import com.tools.ad.strategy.outer.WeatherExecutor;
import com.yanzhenjie.permission.AndPermission;

/**
 * desc: DAP天气广告位，该广告由DAP自行请求，主要用来处理引导
 * date: 2018/4/20
 * author: ancun
 */

public class WeatherScene extends AdScene {

    public WeatherScene(AMApplication context, EntranceType entranceType) {
        super(context, entranceType);
    }

    @Override
    public boolean load(boolean forceLoad) {
        HmWeatherAdPlace weatherAdPlace = HmAdsSDK.getInstance().getDuWeatherAdPlace();
        if (weatherAdPlace == null) {
            return false;
        }

        WeatherExecutor executor = (WeatherExecutor) getADModule().getADStrategyManager().getExecutorByEntranceType(mEntranceType);
        if (forceLoad || executor.check(weatherAdPlace)) {
            if (AndPermission.checkOverlayPermission(imContext)) {
                executor.record();
                imContext.handleMobEmptyMessage(R.id.msg_weather_guide_show);
            }
            return true;
        }
        return false;
    }

    @Override
    public void release() {

    }

    @Override
    public View getAdView() {
        return null;
    }

    protected ADModule getADModule() {
        return (ADModule) imContext.getSubModule(ADModule.MODULE_KEY);
    }
}
